@@ -9,6 +9,10 @@ class Scenario < ActiveRecord::Base |
||
9 | 9 |
|
10 | 10 |
validates_presence_of :name, :user |
11 | 11 |
|
12 |
+ validates_format_of :tag_fg_color, :tag_bg_color, |
|
13 |
+ :with => /\A#(?:[0-9a-fA-F]{3}){1,2}\z/, :message => "must be a valid hex color." |
|
14 |
+ # Regex adapted from: http://stackoverflow.com/a/1636354/3130625 |
|
15 |
+ |
|
12 | 16 |
validate :agents_are_owned |
13 | 17 |
|
14 | 18 |
protected |
@@ -29,6 +29,16 @@ describe Scenario do |
||
29 | 29 |
new_instance.should_not be_valid |
30 | 30 |
end |
31 | 31 |
|
32 |
+ it "validates tag_fg_color is hex color" do |
|
33 |
+ new_instance.tag_fg_color = '#N07H3X' |
|
34 |
+ new_instance.should_not be_valid |
|
35 |
+ end |
|
36 |
+ |
|
37 |
+ it "validates tag_bg_color is hex color" do |
|
38 |
+ new_instance.tag_bg_color = '#N07H3X' |
|
39 |
+ new_instance.should_not be_valid |
|
40 |
+ end |
|
41 |
+ |
|
32 | 42 |
it "only allows Agents owned by user" do |
33 | 43 |
new_instance.agent_ids = [agents(:bob_website_agent).id] |
34 | 44 |
new_instance.should be_valid |